//
// Created by T758 on 2021/06/16.
//

#include "food.h"
#include <curses.h>


Food::Food(Wall &tempwall) :wall(tempwall)
{}

void Food::setFood()
{

    while (true)
    {
        FoodX = rand() % (Wall::ROW - 2) + 1;
        FoodY = rand() % (Wall::COL - 2) + 1;
        //如果随机的位置是蛇头或蛇身，就重新生成随机数
        if (wall.getWall(FoodX, FoodY) == ' ')
        {
            wall.setWall(FoodX, FoodY, '#');
            ::move(FoodY * 2, FoodX);
            cout << '#';
            break;
        }
    }
}
